#ifndef FILEPARSER_H
#define FILEPARSER_H

#include <QObject>
#include <QList>
#include <QStringList>
#include <QMap>
#include <QUrl>

#include "fileinfo.h"

const QStringList FILENUM_KEY_LIST = {"picture",       "video",       "music",       "document",
                                      "qqPicture",     "qqVideo",     "qqMusic",     "qqDocument",
                                      "wechatPicture", "wechatVideo", "wechatMusic", "wechatDocument"};
class FileParSer : public QObject
{
    Q_OBJECT
public:
    FileParSer(QUrl url, QObject *parent = nullptr);
    ~FileParSer();

    // 读取配置，获取分类列表项数
    void getItemCountList(QString path, QMap<QString, int> &map);

    // 获取文件信息
    void getFileInfoList(QString path, QList<FileInfo> &fileList, QString flag = "");

    // 获取缩略图列表
    void getThumbList(QString path, QStringList &list);

    // 判断当前文件是否需要更新
    bool isNeedUpdate(QString sourceFile, QString targetData, QString key = "");

    bool setKeyItemInfo(QString path, QString key);

private:
    enum KEY_INDEX {
        KEYNAME = 0, // 名称
        NUM,         // 数量
        VERSION,     // 版本
        ISUPDATE     // 是否需要更新
    };
    QString getTimeStamp(QString data, QString key = "");
    bool writeNumInfo(QFile *file, QString data);
    QString addAllItemInfo(QString data);
    QString updateItemInfo(QString sourceData, QString targetData, QString key = "");
    QString updateItem(QString data, QString key);
    bool getIsUpdate(QString data, QString key);
    void setInfoMap(QString data, QMap<QString, QString> &map);

private:
    QUrl m_url; // 服务器地址
Q_SIGNALS:

public Q_SLOTS:
};

#endif // FILEPARSER_H